#include <stdio.h>
#include <stdlib.h>
//typedef struct stackNode* link;
typedef struct stackNode{
    int data;   
    struct stackNode *prev, *next;
} stackNode, *link;


/*
typedef struct stackNode* link;
typedef struct stackNode{	//好2啊，这里把stack 打成了 stcak 结果报错了半天...
	int data;
	struct stackNode *prev, *next;
}stackNode;
*/
link head, tail;
void stackInitial(){
	head = tail = NULL;
}
link newNode(int in){
	link temp = (link)malloc(sizeof(stackNode));
	temp->data = in;
	temp->next = temp->prev = temp;
	return temp;
}
void stackPush(int in){
	if(head == NULL){
		head = tail = newNode(in);
	}else{
		link temp = newNode(in);
		temp->next = tail->next;
		temp->prev = tail;
		tail->next->prev = temp;
		tail->next = temp;
		tail = temp;
	}
}
void stackPop(){
	int re = tail->data;
	link temp = tail;
	tail->prev->next = tail->next;
	tail->next->prev = tail->prev;
	tail = tail->prev; 	//这一句刚刚忘记写了，导致每次取出都是对同一块内存访问，即使已经free，所以BUG
	free(temp);
	printf("%d\n", re); 
}
int main(){
	stackInitial();
	stackPush(1);
	stackPush(2);
	stackPush(3);
	stackPush(4);
	stackPush(5);
	stackPop();	
	stackPop();	
	stackPop();	
	stackPop();	
	stackPop();	


}
